/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.devmng.service;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.devmng.dao.TaskExecRecordAttaDao;
import com.thinkgem.jeesite.modules.devmng.entity.TaskExecRecordAtta;
import com.thinkgem.jeesite.modules.devmng.vo.GetTaskDetailResponse;
import com.thinkgem.jeesite.modules.devmng.vo.TaskDetailAttaVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 任务执行记录附件表Service
 *
 * @author panda
 * @version 2017-12-08
 */
@Service
@Transactional(readOnly = true)
public class TaskExecRecordAttaService extends CrudService<TaskExecRecordAttaDao, TaskExecRecordAtta> {

    public TaskExecRecordAtta get(String id) {
        return super.get(id);
    }

    public List<TaskExecRecordAtta> findList(TaskExecRecordAtta taskExecRecordAtta) {
        return super.findList(taskExecRecordAtta);
    }

    public Page<TaskExecRecordAtta> findPage(Page<TaskExecRecordAtta> page, TaskExecRecordAtta taskExecRecordAtta) {
        return super.findPage(page, taskExecRecordAtta);
    }

    @Transactional(readOnly = false)
    public void save(TaskExecRecordAtta taskExecRecordAtta) {
        super.save(taskExecRecordAtta);
    }

    @Transactional(readOnly = false)
    public void delete(TaskExecRecordAtta taskExecRecordAtta) {
        super.delete(taskExecRecordAtta);
    }

    public GetTaskDetailResponse getTaskDetail(String taskMainId, String deviceMainId, String devchkItemId) {
        GetTaskDetailResponse response = new GetTaskDetailResponse();
        TaskExecRecordAtta query = new TaskExecRecordAtta();
        query.setTaskMainId(taskMainId);
        query.setDeviceMainId(deviceMainId);
        query.setDevchkItemId(devchkItemId);
        List<TaskExecRecordAtta> list = this.dao.findList(query);
        if (list.size() == 0) {
            return response;
        }

        List<String> imgList = new ArrayList<>();
        for (TaskExecRecordAtta atta : list) {
            imgList.add(atta.getAttaUrl());
        }
        TaskDetailAttaVo vo = new TaskDetailAttaVo();
        vo.setTitle("图片");
        vo.setUrlList(imgList);

        response.setTaskDetailAttaVo(vo);
        return response;
    }



}